﻿using SF.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SF.Web.UI.pageCs
{
    public class goodList
    {
        /// <summary>
        /// 加载商品列表Html
        /// </summary>
        /// <returns></returns>
        public string LoadGoodListHtml(string goodTypeId)
        {
            string result = string.Empty;

            //如果没传入goodTypeId，则取首个分类（首页可能不传goodTypId）
            if (String.IsNullOrWhiteSpace(goodTypeId))
            {
                BLL.bs_good_type goodTypeBll = new BLL.bs_good_type();
                var firstGoodType = goodTypeBll.GetFirstModel();
                if (firstGoodType != null)
                {
                    goodTypeId = firstGoodType.id.ToString();
                }
            }

            BLL.bs_good_info goodBll = new BLL.bs_good_info();
            //分类下未禁用的商品
            string strWhere = string.Format("goodTypeId='{0}' and status='onSale'", goodTypeId);
            var goodList = goodBll.GetModelList(strWhere);
            if (goodList != null && goodList.Any())
            {
                StringBuilder sbHtml = new StringBuilder();

                foreach (var good in goodList.OrderBy(m => m.sort).ThenByDescending(m => m.lastTime))
                {
                    string goodHot = Utils.GetEnumDescription((SF.Common.DTEnums.GoodHotEnum)Enum.Parse(typeof(SF.Common.DTEnums.GoodHotEnum), good.goodHot));
                    string strLi = string.Format(@"<li id='product-item-{0}' class='xiang-0' data-model='0'>
                                <div id='normal-18731' class='product-item-box'>
                                    <div class='product-item-inner'>
                                        <div class='product-item-header'>
                                            <div class='lazy-wrap font-zero'>
                                                <a href='http://m2.bingofresh.com/v3.7/home.php#/product_view/normal/18731' class='tabBox' id='productSwitch18731' title='{1}' data-status='0' data-lock='unlock' onclick='common.buttonClikcStatistics(&#39;index&#39;,&#39;index_view&#39;,&#39;产品大图&#39;);' style='height: 180px;'>
                                                    <ul style='width: 718px;'>
                                                        <li style='width: 359px; height: 180px;'>
                                                            <img class='lazy' src='{2}' data-model='0' width='100%' alt='{3}'></li>
                                                    </ul>
                                                </a>
                                            </div>
                                        </div>
                                        <div class='product-item-main'>
                                            <div class='product-item-content'>
                                                <h3><a href='http://m2.bingofresh.com/v3.7/home.php#/product_view/normal/18731' title='{4}'>{5}</a>     </h3>
                                                <p class='subtitle'>{6}</p>
                                                <p id='product-itme-price-box-18731' class='product-itme-price-box'><span class='price'><i>¥</i>{7}</span> <span class='unit'>/ 每一份</span> </p>
                                                <p class='product-item-subtotal-box'><i>x</i> <em id='item_num_18731' class='num'></em><i>小计 ¥</i> <em id='item_subtotal_18731'></em></p>
                                            </div>
                                            <div class='product-opera-wrap'>
                                                <div class='product-opera-inner' id='product-opera-inner-18731'>
                                                    <div class='product-buy-oprea' id='product-buy-oprea-18731'><span class='btn active-btn' onclick='subtractBtn(18731)'><i class='icon-minus'></i></span><span class='btn active-btn' onclick='plusBtn(18731)'><i class='icon-plus'></i></span></div>
                                                    <span class='btn active-btn' id='product-buy-btn-18731' onclick='plusBtn(18731,event)'>买</span>
                                                    <img class='product-thu-img hide' src='images/14767592990.jpg' width='0' height='0' alt='会员专享-新疆库尔勒香梨'>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>", good.id, good.name, good.showImage, good.name, good.name, good.name, goodHot, good.sellPrice);
                    sbHtml.Append(strLi);
                }
                result = sbHtml.ToString();
            }
            return result;
        }
    }
}
